/**
 * 已将方法挂载全局，$setGrapData
 * @param {*} obj1 第一个参数
 * @param {*} obj2 第二个参数：为拟合数据
 * @param {*} obj3 第三个参数：为优化数据
 * @returns 拟合，平滑数据
 */
export function setGrapData(obj1, obj2 = {}, obj3 = {}) {
  // 最终的返回结果
  let resultList = {}
  // 所有的key
  let keyList = []
  // 如果为多个需要合并处理
  let newObj = {}
  // 处理后的第二个对象
  let nObj2 = {}
  if(obj2.time) {
    for (const k in obj2) {
      if(k !== 'time' ) {
        nObj2[`拟合${k}`] = obj2[k]
      }
    }
    newObj = { ...obj1, ...nObj2}
  } else {
    newObj = obj1
  }

  let nObj3 = {}
  if(obj3.time) {
    for (const k in obj3) {
      if(k !== 'time' ) {
        nObj3[`平滑${k}`] = obj3[k]
      }
    }
    newObj = { ...newObj, ...nObj3}
  }

  const timeList = newObj.time
  for (const k in newObj) {
    if (k !== 'time') {
      keyList.push(k)
      let arr = []
      for (let i = 0; i < newObj[k].length; i++) {
        arr.push([timeList[i], newObj[k][i]])
      }
      resultList[k] = arr
    }
  }
  resultList['time'] = timeList
  return {
    resultList: [resultList],
    keyList
  }
}

export function setGrapDataTwo(obj1, obj2 = {}, obj3 = {}) {
  // 最终的返回结果
  let resultList = {}
  // 所有的key
  let keyList = []
  // 如果为多个需要合并处理
  let newObj = {}
  // 处理后的第二个对象
  let nObj2 = {}
  if(obj2.time) {
    for (const k in obj2) {
      if(k !== 'time' ) {
        nObj2[`拟合${k}`] = obj2[k]
      }
    }
    newObj = { ...obj1, ...nObj2}
  } else {
    newObj = obj1
  }

  let nObj3 = {}
  if(obj3.time) {
    for (const k in obj3) {
      if(k !== 'time' ) {
        nObj3[`优化${k}`] = obj3[k]
      }
    }
    newObj = { ...newObj, ...nObj3}
  }

  const timeList = obj1.time || obj2.time || obj3.time
  for (const k in newObj) {
    if (k !== 'time') {
      keyList.push(k)
      let arr = []
      for (let i = 0; i < newObj[k].length; i++) {
        arr.push([timeList[i], newObj[k][i]])
      }
      resultList[k] = arr
    }
  }
  resultList['time'] = timeList
  return {
    resultList: [resultList],
    keyList
  }
}